export default defineEventHandler(async (event) => {
  const { page = 1, pageSize = 10 } = getQuery(event)
  
  // 模拟已购买的产品数据
  const allDownloads = [
    {
      id: 'dl1',
      userId: 'user1',
      product: {
        id: '1',
        title: 'Vue3 + Vite 后台管理系统',
        description: '基于 Vue3、Vite、TypeScript、Element Plus 的后台管理系统，包含权限管理、数据可视化等功能',
        price: 299,
        originalPrice: 599,
        cover: 'https://picsum.photos/seed/admin-system/600/400',
        category: 'frontend',
        tags: ['Vue3', 'TypeScript', 'Element Plus'],
        tech: ['Vue3', 'Vite', 'TypeScript', 'Element Plus', 'Pinia'],
        difficulty: 'intermediate' as const,
        rating: 4.8,
        reviews: 128,
        downloads: 1580,
        createdAt: '2025-01-01',
        updatedAt: '2025-01-10',
        images: ['https://picsum.photos/seed/admin-system/600/400'],
      },
      purchasedAt: '2025-01-10 10:35:00',
      downloadCount: 3,
      lastDownloadAt: '2025-01-15 14:20:00',
    },
    {
      id: 'dl2',
      userId: 'user1',
      product: {
        id: '4',
        title: 'NestJS + TypeORM 企业级后端',
        description: '企业级 RESTful API 项目，包含认证授权、数据库操作、文件上传等功能',
        price: 599,
        originalPrice: 1299,
        cover: 'https://picsum.photos/seed/backend/600/400',
        category: 'backend',
        tags: ['NestJS', 'TypeScript', 'MySQL'],
        tech: ['NestJS', 'TypeScript', 'TypeORM', 'MySQL', 'Redis'],
        difficulty: 'advanced' as const,
        rating: 4.9,
        reviews: 178,
        downloads: 1876,
        createdAt: '2025-01-03',
        updatedAt: '2025-01-09',
        images: ['https://picsum.photos/seed/backend/600/400'],
      },
      purchasedAt: '2025-01-08 16:20:00',
      downloadCount: 1,
      lastDownloadAt: '2025-01-08 16:25:00',
    },
  ]
  
  // 分页
  const pageNum = Number(page)
  const pageSizeNum = Number(pageSize)
  const start = (pageNum - 1) * pageSizeNum
  const end = start + pageSizeNum
  const items = allDownloads.slice(start, end)
  
  return {
    code: 200,
    message: 'success',
    data: {
      items,
      pagination: {
        page: pageNum,
        pageSize: pageSizeNum,
        total: allDownloads.length,
        totalPages: Math.ceil(allDownloads.length / pageSizeNum),
      },
    },
  }
})

